import request from '@/utils/request'
import { Axios, AxiosResponse } from 'axios'
import { AddTaskByWeeklyPlanParams } from '@/api/weeklyplan/type'
// 项目用户相关的请求地址
enum WeeklyPlan_API {
  GET_WeeklyPlans = '/transaction_assistant/weekly-plan/list',
  POST_ADD_WeeklyPlans = '/transaction_assistant/weekly-plan/add/{planName}',
  POST_CHANGE_WeeklyPlans_NAME = '/transaction_assistant/weekly-plan/change-name/{id}/{planName}',
  POST_ADD_Task_BY_WeeklyPlans = '/transaction_assistant/weekly-plan/addTask',
  GET_WeeklyPlan_Id = '/transaction_assistant/weekly-plan/getIdByName/{planName}',
  Delete_WeeklyPlan = '/transaction_assistant/weekly-plan/delete/{id}',
  Get_Task_From_Plan = '/transaction_assistant/weekly-plan/task-list/{id}',
}

/**
 * 获取个人周计划列表
 */
export const getWeeklyPlans = () => {
  return request.get<any, AxiosResponse<any>>(WeeklyPlan_API.GET_WeeklyPlans)
}
/**
 * 增加个人周计划
 */
export const addWeeklyPlan = (planName: string) => {
  return request.post<any, AxiosResponse<any>>(
    WeeklyPlan_API.POST_ADD_WeeklyPlans.replace('{planName}', planName),
  )
}

/**
 * 修改周计划名
 */
export const changeWeeklyPlanName = (id: number, planName: string) => {
  return request.post<any, AxiosResponse<any>>(
    WeeklyPlan_API.POST_CHANGE_WeeklyPlans_NAME.replace(
      '{id}',
      id,
      '{planName}',
      planName,
    ),
  )
}
/**
 * 周计划事务添加
 */
export const addTaskByWeeklyPlan = (params: AddTaskByWeeklyPlanParams) => {
  return request.post<any, AxiosResponse<any>>(
    WeeklyPlan_API.POST_ADD_Task_BY_WeeklyPlans,
    params,
  )
}

/**
 * 根据名称获取周计划id
 */
export const getWeeklyPlanIdByName = (planName: string) => {
  return request.get<any, AxiosResponse<any>>(
    WeeklyPlan_API.GET_WeeklyPlan_Id.replace('{planName}', planName),
  )
}

/**
 * 删除周计划
 */
export const deleteWeeklyPlanById = (id: number) => {
  return request.delete<any, AxiosResponse<any>>(
    WeeklyPlan_API.Delete_WeeklyPlan.replace('{id}', id),
  )
}

/**
 * 获取周计划事务
 */
export const getTaskFromWeeklyPlan = (id: number) => {
  return request.get<any, AxiosResponse<any>>(
    WeeklyPlan_API.Get_Task_From_Plan.replace('{id}', id),
  )
}
